Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
Function is no longer found if I add "require" source

I have a function "loadDays()" that should be executed when the body-section is loaded:

<body onload="loadDays()">

In <script> I have my function loadDays():

<script>
    function loadDays() {
        // code
    }

Now I added src="https://requirejs.org/docs/release/2.3.5/minified/require.js" to the <script>-tag, to make use of require inside my function.

While it does recognize require then, it throws a new error:

"Uncaught ReferenceError: loadDays is not defined

at onload

What am I missing?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

If <script> tag has src attribute, then any content inside this tag is ignored.

You should add 2 separate tags:

<script src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>
<script>
    function loadDays() {
        // code
    }
</script>

about 4 years ago · Juan Pablo Isaza Denunciar

0

I've checked requireJS, so you should actually do it like this, as they said in the docs:

<!DOCTYPE html>
<html>
    <head>
        <title>My Sample Project</title>
        <!-- data-main attribute tells require.js to load
             scripts/main.js after require.js loads. -->
        <script data-main="scripts/main" src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>
    </head>
    <body>
        <h1>My Sample Project</h1>
    </body>
</html>

Then add a main.js file in the scripts folder, and put your function inside of it.

    function loadDays() {
        // code
    }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda